<?php
class BL_GestorArchReportes{
	private $arrReportes = null;
	private $arrApps = null;
	private $arrVentanas = null;
	private $arrReporteLineas = null;
	
	private $arrObjArchReporte = null;
	private $rutaDirectorio = null;
	private $nomArchsReporte = null;
	private $error = null;
	
	public function BL_GestorArchReportes($rutaDirectorio){		
		
	}

	public function procesarReportes() {
		$this->arrReportes = array();
		$this->arrApps = array();
		$this->arrVentanas = array();
		$this->arrReporteLineas = array();
		
		$internalID = 0;
		foreach ($this->arrObjArchReporte as $objArchReporte) {
			$reporte = new Reporte(
			$internalID,
			$objArchReporte->getNombre(),
			$objArchReporte->getLineas(),
			$this->arrApps,
			$this->arrVentanas
			);
			if($reporte->getError()->noHayError()){					
				$this->arrReportes[] = array(
					'idReporteBD'=>0,
					'idReporteLocal'=>$internalID,
					'nomArch'=>$objArchReporte->getNombre(),
					'fecha'=>$reporte->getFecha(),
					'idComputer'=>$reporte->getIdComputer(),
					'user'=>$reporte->getUser(),
					'numLineas'=>$reporte->getNumLineas()
				);
				$internalID++;				
				
				$this->arrApps = $reporte->getArrApps();
				$this->arrVentanas = $reporte->getArrVentanas();
				$this->arrReporteLineas = array_merge(
					$this->arrReporteLineas,
					$reporte->getArrReporteLineas()
				);
			}							
			else{
				$this->error = $reporte->getError();
				break;					
			}
		}
	}
	
	public function getNomArchsReporte(){
		return $this->nomArchsReporte;
	}
	
	public function getReportes(){
		return $this->reportes;
	}
	
	public function getError(){
		return $this->error;
	}
	
	
	public function imprimir() {
		echo '<pre>';
		foreach ($this->arrReportes as $reporte) {
			echo 'Reporte '.$reporte['idReporteLocal'].':<br>';
			echo 'Nombre de archivo: '.$reporte['nomArch'].'<br>';
			echo 'Fecha: '.$reporte['fecha'].'<br>';
			echo 'ID Computer: '.$reporte['idComputer'].'<br>';
			echo 'User: '.$reporte['user'].'<br>';
			echo 'Total Registros: '.$reporte['numLineas'].'<br><br>';			
		}
		echo '------------------------------------------------------<br>';
		/*
		$idAnterior = 0;
		foreach ($this->arrReporteLineas as $reporteLinea) {
			if ($reporteLinea['idVentanaLocal']==4){				
				//echo 'IdReporte: '.$reporteLinea['idReporteLocal'];
				//echo ' IdReporteLinea: '.$reporteLinea['idReporteLineaLocal'];
				//echo ' IdVentanaLocal: '.$reporteLinea['idVentanaLocal'];			
				//echo ' IdReporteLinea: '.$reporteLinea['idReporteLineaLocal'];
				//echo ' LineaTitulo: '.$reporteLinea['lineaTitulo'];
				if($reporteLinea['idReporteLineaLocal']-$idAnterior>1){
					echo $reporteLinea['lineaTitulo'].'<br>';
				}		
				$idAnterior = $reporteLinea['idReporteLineaLocal'];
				echo $reporteLinea['hora'].' - '.$reporteLinea['contenido'];
				echo '<br>';			
			}
		}*/			
		echo '</pre>';
	}
	
	public function getArrReportes(){
		return $this->arrReportes;
	}
	
	public function getArrApps(){
		return $this->arrApps;
	}
	
	public function getArrVentanas(){
		return $this->arrVentanas;
	}
	
	public function getArrReporteLineas(){
		return $this->arrReporteLineas;
	}
	
	private function guardarArrApps() {
		include 'utilidades/ReporteBD.php';
		$reporteBD = new ReporteBD();
		if($reporteBD->getError()->noHayError()){
			$arrNomApps = array_keys($this->obtenerArrApps());
			$this->arrApps = $reporteBD->guardarArrApps($arrNomApps);					
		}
		$this->error = $reporteBD->getError();
	}
	
}